//从仓库获取轮播图信息
$(function(){
    slides=JSON.parse(localStorage.getItem("slides"));
    var divCarousel=$("#lunbo");
    console.log(divCarousel);
    for(var i=0;i<slides.length;i++){
        var divs=$("<div><img src='imgs/slides/"+slides[i]+"' style='width: 100%; height: 600px;'></div>");
        divCarousel.append(divs);
    }
});

//从仓库获取图书信息(图书查询)
$(function(){
    guessLikes=JSON.parse(localStorage.getItem("guessLikes"));
    var tbody=$("tbody");
    for(var i=0;i<guessLikes.length;i++){
        // var num=$("tbody tr").length+1;
        var title=guessLikes[i].title;
        var author=guessLikes[i].author;
        var publishing=guessLikes[i].publishing;
        var img=guessLikes[i].img;
        console.log(img);
        //此处图片有BUG，需要修复
        var tr=$("<tr><td>"+title+"</td><td>"+author+"</td><td>"+publishing+"</td><td><img src='imgs/guessLikes/"+img+"' alt='无法显示图片'></td></tr>")
        tbody.append(tr);
    }
});


//搜索图书
$(function(){
    $("input:eq(0) + div").click(function(){
        var guessLikes=JSON.parse(localStorage.getItem("guessLikes"));
        var title=[];//将所有title放在一起
        for(var i=0;i<guessLikes.length;i++){
            title.push(guessLikes[i].title);
        }
        var titleSearch=$("input:eq(0)").val();
        var index=title.indexOf(titleSearch);//根据输入的title查找，返回索引，根据索引找到对应的其他数据，后续存入表格
        console.log(index);
        ////////////////
        var tbody=$("tbody");
        tbody.children().remove();//将表格中的所有行删除，后面再添加查找到的行
        var tr=$("<tr><td>"+guessLikes[index].title+"</td><td>"+guessLikes[index].author+"</td><td>"+guessLikes[index].publishing+"</td><td><img src='imgs/guessLikes/"+guessLikes[index].img+"'></td></tr>")
        tbody.append(tr);
    });
});